package com.headhunter.portlet.dao.impl;

import java.util.List;
import org.springframework.stereotype.Repository;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.headhunter.portlet.dao.VocationDAO;
import com.headhunter.portlet.domain.Vocation;

/**
 * Implementation of <code>VocationDao</code> using JPA Entity Manager.
 * 
 * @author Dmitriy Ilchenko
 */
@Repository
public class VocationDAOImpl implements VocationDAO {

	@PersistenceContext
	protected EntityManager em;

	public List<Vocation> getVocationsListOrderByDate() {
		Query query = em.createQuery("SELECT v FROM Vocation v ORDER BY start_date DESC");
		List<Vocation> result = query.getResultList();
		return result;
	}
	
	public void addVocation(Vocation v) {
		em.merge(v);
	}
}
